package com.lihui.removeduplicates;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/09/29  9:25
 */
public class RemoveNum {
    public static void main(String[] args) {
        int[] nums = {1,1,2,2,4,4,6,6};
        Solution solution = new Solution();
        System.out.println(solution.removeDuplicates(nums));
    }
}
class Solution {
    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 1){
            return nums.length;
        }
        int left = 0;
        int right = 1;
       while (right < nums.length) {
           if (nums[left] == nums[right]) {
               right++;
           } else {
               left++;
               nums[left] = nums[right];
               right++;
           }
       }
       return left + 1;
    }
}
